<?php
namespace Home\Controller;

class TrainController extends HomeController {

    public function index(){

        $cate = I('get.cate');
        
        if ($cate!='') {
            if (!is_numeric($cate)) {
                $this->error('参数错误');
            }
            $map['cid'] = $cate;
        }else{
            $map['path'] = array('like','0-4-%');
        }
        $this->assign('cateID',$cate);
        $map['del'] = 0;
        $map['status'] = 1;
        $obj = M('Article');
        $count = $obj->where($map)->count();
        import("common.ORG.AmPage");
        $page = new \Page($count, 25);
        $show = $page->show();
        $list = $obj->where($map)->order('createTime desc,id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->assign('cate',$cate);

        $banner = M("Ad")->where(array('id'=>10))->find();
        $this->assign('banner',$banner);
        $this->display();

    }  

    public function view(){
    	$id = I('get.id');
        if ($id=='' || !is_numeric($id)) {
            $this->error('参数错误');
        }

        $map['id'] = $id;
        $map['status'] = 1;
        $map['del'] = 0;        
        $list = M('Article')->where($map)->find();
        if (!$list) {
            $this->error('文章不存在');
        }else{
            M('Article')->where($map)->setInc('hit');

            $this->assign('list', $list);

            $banner = M("Ad")->where(array('id'=>10))->find();
            $this->assign('banner',$banner);
            $this->display();
        }
    }
}